﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.OleDb;
using System.IO;

namespace DiaryPlanner
{
    public partial class Album : UserControl
    {

        public ArrayList FolderList = new ArrayList();//폴더들을 관리하는 리스트
        public AlbumFolder nowFolder;//현재 지정된 폴더
        public AlbumPhoto nowPhoto;//현재 지정된 사진


       
        public Album()
        {
            InitializeComponent();
       
            
            try//Album 폴더 생성
            {
                // If the directory doesn't exist, create it.
                if (!Directory.Exists("Album"))
                {
                    Directory.CreateDirectory("Album");
                }
            }
            catch (Exception)
            {
                // Fail silently
            }


            viewAllFolder();
            viewAllPhoto();

        }

        private void btnFolderAdd_Click(object sender, EventArgs e)
        {
            AlbumAddFolder aaf = new AlbumAddFolder(this);//새 폴더를 추가하는 다이얼로그
            aaf.ShowDialog();
            aaf = null;
        }


        public void viewAllPhoto() {

            photoPanel.Controls.Clear();

            if (nowFolder == null) {
                return;
            }

            int i = 0;
            foreach (AlbumPhoto af in nowFolder.PhotoList)
            {
                //Label lb = new Label();//폴더 이름
                //lb.Text = af.folderName;
                //lb.Size = new Size(70, 12);
                //folderPanel.Controls.Add(lb);
                //lb.Location = new Point(5, 60 + 70 * i);

                photoPanel.Controls.Add(af);//사진
                
                af.Location = new Point(5 + 105 * (i % 3), 5 + 105 * (i / 3));

                i++;
            }

            photoPanel.Controls.Add(btnPhotoAdd);//사진 추가 버튼
            btnPhotoAdd.Location = new Point(5 + 105 * (i % 3), 5 + 105 * (i / 3));

        }


        public void viewAllFolder() {
            
                
            folderPanel.Controls.Clear();

            //폴더 리스트의 모든 폴더
            int i = 0;
            foreach(AlbumFolder af in this.FolderList){

                Label lb = new Label();//폴더 이름
                lb.Text = af.folderName;
                lb.Size = new Size(70, 12);
                folderPanel.Controls.Add(lb);
                lb.Location = new Point(5, 60 + 70 * i);

                folderPanel.Controls.Add(af);//폴더
                af.Location = new Point(5, 5+70*i);

                i++;
                
            }

            folderPanel.Controls.Add(btnFolderAdd);//폴더 추가 버튼
            btnFolderAdd.Location = new Point(5, 10 + 70 * i);
        }

        private void btnPhotoAdd_Click(object sender, EventArgs e)
        {
            AlbumAddPhoto aaf = new AlbumAddPhoto(this);//새 사진를 추가하는 다이얼로그
            aaf.ShowDialog();
        }

    }
}
